from typing import Dict, List, Optional

class Vocab:
    def __init__(self, words: List[str]):
        self.encode: Dict[str, int] = {}
        self.decode: Dict[int, str] = {}
        self.words: List[str] = words
        
        for i, word in enumerate(words):
            self.encode[word] = i
            self.decode[i] = word
    
    def encode_word(self, word: str) -> Optional[int]:
        """Convert a word to its token index"""
        return self.encode.get(word)
    
    def decode_word(self, token_id: int) -> Optional[str]:
        """Convert a token index back to a word"""
        return self.decode.get(token_id)
    
    @staticmethod
    def default_words() -> List[str]:
        return ["hello", "world", "this", "is", "rust", "</s>"]
    
    @classmethod
    def default(cls) -> 'Vocab':
        return cls(cls.default_words())